<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>

<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch" data-options="{searchDatagrid:$.CurrentNavtab.find('#admin_log_table')}">
        <fieldset>
            <legend style="font-weight:normal;">条件搜索：</legend>
            <div style="margin:0; padding:1px 15px 15px;">
                <label class="row-label">用户名：</label>
                <input type="text" name="userName" class="form-control" size="11">
                    
                <label class="row-label">操作时间：</label>
                <input type="text" name="fromTo.from" data-toggle="datepicker" data-nobtn="true" size="11">
                <label class="row-label">-</label>
                <input type="text" name="fromTo.to" data-toggle="datepicker" data-nobtn="true" size="11">

                <label class="row-label">&nbsp;&nbsp;&nbsp;&nbsp;日志类型：</label>
                <select data-toggle="selectpicker" name="type" data-width="110">
                    <option value="正常" selected>正常</option>
                    <option value="非法请求">非法请求</option>
                    <option value="服务器错误">服务器错误</option>
                    <option value="未知错误">未知错误</option>
                </select>
                    <label class="row-label"></label>
                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">搜索</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table id="admin_log_table" class="table table-bordered">
    </table>
    <script type="text/javascript">
        var admin_log_table;
        $(function () {
            admin_log_table = $('#admin_log_table').datagrid({
                height: '100%',
                width: '100%',
                fullGrid : true,
                showToolbar: true,
                filterThead: false,
                delPK: 'id',
                dataUrl: '/admin/log/allLog?handler=ADMIN&_=' + new Date().getTime(),
                local: "remote",
                inlineEditMult: false,
                saveAll: false,
                addLocation: 'last',
                toolbarItem: 'refresh',
                toolbarCustom: function () {
                    return '<button type="button" class="btn btn-green" onclick="adminLogExport();" data-icon="sign-out"><i class="fa fa-sign-out"></i> 导出</button>';
                },
                delConfirm: true,
                columns: [
                    {
                        name: 'title',
                        label: '标题',
                        align: 'center'
                    }, {
                        render: adminLogShowUser,
                        label: '用户名',
                        align: 'center'
                    }, {
                        name: 'pageType',
                        label: 'URL类型',
                        align: 'center'
                    }, {
                        name: 'remoteAdder',
                        label: 'IP地址',
                        align: 'center'
                    }, {
                        name: 'requestUri',
                        label: 'URL',
                        align: 'left'
                    }, {
                        name: 'method',
                        label: 'Method',
                        align: 'center'
                    }, {
                        name: 'params',
                        label: '参数',
                        align: 'left',
                        render: function (value) {
                            return value ? (value.length > 10 ? value.substr(0, 10) + '...': value) : value
                        }
                    }, {
                        name: 'userAgent',
                        align: 'center',
                        label: '浏览器'
                    }, {
                        name: 'os',
                        align: 'center',
                        label: '操作系统'
                    }, {
                        name: 'elapsed',
                        align: 'center',
                        label: '耗时'
                    }, {
                        name: 'exception',
                        align: 'left',
                        label: '异常',
                        render: function (value) {
                            return value ? (value.length > 10 ? value.substr(0, 10) + '...': value) : value
                        }
                    }, {
                        name: 'responseCode',
                        label: '响应码',
                        align: 'center'
                    }, {
                        name: 'beginDate',
                        label: '开始',
                        align: 'center',
                        pattern: 'yyyy-MM-dd HH:mm:ss',
                        render: function (value) {
                            return value ? value.substr(0, 19) : value
                        }
                    }, {
                        name: 'endDate',
                        label: '结束',
                        align: 'center',
                        pattern: 'yyyy-MM-dd HH:mm:ss',
                        render: function (value) {
                            return value ? value.substr(0, 19) : value
                        }
                    }, {
                        render: adminLogShowJson,
                        label: '操作',
                        align: 'center'
                    }
                ],
                linenumberAll: true,
                paging: {pageSize: 20, pageIndex: 1}
            });
        });


        function adminLogExport() {
            var dates = $(admin_log_table).data('selectedDatas');
            if (dates && dates.length !== 0) {
                var ids = [];
                dates.forEach(function (e) {
                    ids.push(e.id);
                });
                BJUI.ajax('ajaxdownload', {
                    url: '/admin/log/export',
                    data: {ids: ids.join(",")}
                });
            } else
                BJUI.alertmsg('info', BJUI.getRegional('datagrid.selectMsg'))
        }


        function adminLogShowUser(value, data) {
            if(data.userName !== null && data.userName !== ""
                && data.userName !== undefined && typeof (data.userName) !== 'undefined'){
                return '<a href="javascript:;" onclick="adminLogOpenDialog(\'' + data.userName + '\')">' + data.userName + '</a>';
            }
            return '';
        }

        function adminLogShowJson(value, data) {
            return '<a href="javascript:;" onclick="adminLogPromptJson(\'' + JSON.stringify(data).replace(/\"/g, "&rsquo;") + '\')">查看Json</a>';
        }

        function adminLogPromptJson(data) {
            prompt(data.replace(/\’/g, "\""), data.replace(/\’/g, "\""));
        }

        function adminLogOpenDialog(userName) {
            BJUI.dialog({
                id: 'operatorInfoAdmin',
                url: '/admin/operator/operatorInfo?userName=' + userName,
                title: '' + userName + '管理员信息',
                width: 800,
                height: 500,
                fresh:true
            });
        }
    </script>
</div>
